<!DOCTYPE html>

<html lang="en">
<head>
	<meta charset="utf-8">
	<meta name="viewport" content="width=device-width">
	<title>Documentation Source: utils/utils.js</title>

	<!--[if lt IE 9]>
	<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
	<![endif]-->
	<link type="text/css" rel="stylesheet" href="styles/sunlight.default.css">

	<link type="text/css" rel="stylesheet" href="styles/site.simplex.css">

</head>

<body>

<div class="navbar navbar-default navbar-fixed-top ">
<div class="container">
	<div class="navbar-header">
		<a class="navbar-brand" href="index.html">Documentation</a>
		<button class="navbar-toggle" type="button" data-toggle="collapse" data-target="#topNavigation">
			<span class="icon-bar"></span>
			<span class="icon-bar"></span>
			<span class="icon-bar"></span>
        </button>
	</div>
	<div class="navbar-collapse collapse" id="topNavigation">
		<ul class="nav navbar-nav">
			
			<li class="dropdown">
				<a href="modules.list.html" class="dropdown-toggle" data-toggle="dropdown">Modules<b class="caret"></b></a>
				<ul class="dropdown-menu ">
					<li><a href="module-app.html">app</a></li><li><a href="module-article-card.html">article-card</a></li><li><a href="module-article-detail.html">article-detail</a></li><li><a href="module-article-item.html">article-item</a></li><li><a href="module-article-module.html">article-module</a></li><li><a href="module-back.html">back</a></li><li><a href="module-banner-module.html">banner-module</a></li><li><a href="module-bestseller-module.html">bestseller-module</a></li><li><a href="module-bestseller-product-card.html">bestseller-product-card</a></li><li><a href="module-detail-recommend-module.html">detail-recommend-module</a></li><li><a href="module-discovery.html">discovery</a></li><li><a href="module-grid-navs.html">grid-navs</a></li><li><a href="module-header.html">header</a></li><li><a href="module-index.html">index</a></li><li><a href="module-more-product-card.html">more-product-card</a></li><li><a href="module-navs-module.html">navs-module</a></li><li><a href="module-recommend-product.html">recommend-product</a></li><li><a href="module-recommend-product-module.html">recommend-product-module</a></li><li><a href="module-single-product.html">single-product</a></li><li><a href="module-single-product-module.html">single-product-module</a></li><li><a href="module-special-product.html">special-product</a></li><li><a href="module-special-product-module.html">special-product-module</a></li><li><a href="module-title.html">title</a></li><li><a href="module-views.html">views</a></li>
				</ul>
			</li>
			
			<li class="dropdown">
				<a href="global.html" class="dropdown-toggle" data-toggle="dropdown">Global<b class="caret"></b></a>
				<ul class="dropdown-menu ">
					<li><a href="global.html#$t">$t</a></li><li><a href="global.html#appHandle">appHandle</a></li><li><a href="global.html#axiosRequestReject">axiosRequestReject</a></li><li><a href="global.html#axiosRequestResolve">axiosRequestResolve</a></li><li><a href="global.html#axiosResponseReject">axiosResponseReject</a></li><li><a href="global.html#axiosResponseResolve">axiosResponseResolve</a></li><li><a href="global.html#conversionTime">conversionTime</a></li><li><a href="global.html#current_locale">current_locale</a></li><li><a href="global.html#delay">delay</a></li><li><a href="global.html#deleteEmptyValue">deleteEmptyValue</a></li><li><a href="global.html#formaturl">formaturl</a></li><li><a href="global.html#getCurrentDate">getCurrentDate</a></li><li><a href="global.html#getCurrentLocale">getCurrentLocale</a></li><li><a href="global.html#getHiddenProp">getHiddenProp</a></li><li><a href="global.html#getLanguage">getLanguage</a></li><li><a href="global.html#getLanguageForBackEnd">getLanguageForBackEnd</a></li><li><a href="global.html#getLanguageOptions">getLanguageOptions</a></li><li><a href="global.html#getUploadImage">getUploadImage</a></li><li><a href="global.html#getVisibilityChangeEventName">getVisibilityChangeEventName</a></li><li><a href="global.html#i18n">i18n</a></li><li><a href="global.html#imgPreLoad">imgPreLoad</a></li><li><a href="global.html#importStyle">importStyle</a></li><li><a href="global.html#isContained">isContained</a></li><li><a href="global.html#isHidden">isHidden</a></li><li><a href="global.html#loading_toast">loading_toast</a></li><li><a href="global.html#messages">messages</a></li><li><a href="global.html#parseLanguageParameter">parseLanguageParameter</a></li><li><a href="global.html#parseQueryString">parseQueryString</a></li><li><a href="global.html#resizeModal">resizeModal</a></li><li><a href="global.html#setLanguageOptions">setLanguageOptions</a></li><li><a href="global.html#setLocale">setLocale</a></li><li><a href="global.html#setMinHeightToInnerHeight">setMinHeightToInnerHeight</a></li><li><a href="global.html#startLoading">startLoading</a></li>
				</ul>
			</li>
			
		</ul>
        
            <div class="col-sm-3 col-md-3">
                <form class="navbar-form" role="search">
                    <div class="input-group">
                        <input type="text" class="form-control" placeholder="Search" name="q" id="search-input">
                        <div class="input-group-btn">
                            <button class="btn btn-default" id="search-submit"><i class="glyphicon glyphicon-search"></i></button>
                        </div>
                    </div>
                </form>
            </div>
        
	</div>

</div>
</div>


<div class="container" id="toc-content">
<div class="row">

	
	<div class="col-md-12">
	
		<div id="main">
			

		<h1 class="page-title">Source: utils/utils.js</h1>
    
<section>
    <article>
        <pre
            class="sunlight-highlight-javascript linenums">/**
 * 获取当前的时间
 * @return {string} {格式化后的当前时间}
 */
export function getCurrentDate(mode) {
	const current_date = new Date();

	const year = current_date.getFullYear();

	let months = current_date.getMonth() + 1;

	let date = current_date.getDate();

	if (months &lt; 10) {
		months = `0${months}`;
	}

	if (date &lt; 10) {
		date = `0${date}`;
	}

	if (mode) {
		switch (mode) {
		case 'year':

			return year;

		case 'y-m':

			return `${year}-${months}`;

		case 'month':

			return months;

		case 'day':

			return date;

		default:

			break;
		}
	}

	return `${year}-${months}-${date}`;
}

/**
 * 网址格式化
 * @return {Object} {格式化网址之后得到的参数对象}
 */
export function formaturl() {
	const url_info = {};

	const url_object = window.location.href.split('#').pop().split('?').pop();

	url_object.split('&amp;').forEach((url) => {
		const [key, value] = url.split('=');

		if (key) {
			url_info[key] = value;
		}
	});

	return url_info;
}

/**
 * 图片预加载
 * @param  {array} src_arrs {图片链接数组}
 * @return {array} {加载后的图片数组}
 */
export function imgPreLoad(src_arrs) {
	const imgs = [];

	src_arrs.forEach((src, index) => {
		const img = new Image();

		img.src = src;

		imgs[index] = img;
	});

	return imgs;
}

/**
 * 判断a数组是否包含b数组
 * @param  {array} a {判断的a数组}
 * @param  {array} b {判断的b数组}
 * @return {Boolean} {true代表包含，false代表不包含}
 */
export function isContained(a, b) {
	if (!(a instanceof Array) || !(b instanceof Array)) return false;

	if (a.length &lt; b.length) return false;

	const aStr = a.toString();

	for (let i = 0, len = b.length; i &lt; len; i += 1) {
		if (aStr.indexOf(b[i]) === -1) return false;
	}

	return true;
}


/**
 * 图片上传预览
 * @param  {file} file {图片文件}
 * @param  {Object} _image {$refs获取节点}
 */

export function getUploadImage(file, _image) {
	const reader = new FileReader();

	reader.onload = function (event) {
		_image.src = event.target.result;
	};

	reader.readAsDataURL(file);
}

/**
 * 去除对象中的空值
 * @param  {Object} param {需要进行处理的对象}
 * @return {Object} {去除完毕的对象}
 */
export function deleteEmptyValue(param) {
	const query_param = {};

	Object.keys(param).forEach((key) => {
		const value = param[key];
		if (value &amp;&amp; value.length) {
			if (value.length > 0) {
				query_param[key] = value;
			}
		} else if (String(value)) {
			query_param[key] = value;
		}
	});

	return query_param;
}

/**
 *毫秒转化时分秒
 *@param {Number} date {需要转化的毫秒}
 *@return {undefined}
 */
export function conversionTime(date) {
	let hh = Math.floor(date / 3600);
	if (hh &lt; 10) hh = `0${hh}`;
	let mm = Math.floor((date - (hh * 3600)) / 60);
	if (mm &lt; 10) mm = `0${mm}`;
	let ss = Math.floor((date - (hh * 3600)) % 60);
	if (ss &lt; 10) ss = `0${ss}`;
	const time = `${hh}:${mm}:${ss}`;
	return time;
}

/**
 * 调整模态框的水平居中
 * @return {undefined}
 */
export function resizeModal() {
	const modals = [...document.querySelectorAll('.ivu-modal-wrap')];
	if (!modals || modals.length === 0) return;

	const side_menu = document.querySelector('.layout-side-menu');
	modals.forEach((modal) => {
		modal.style.paddingLeft = `${side_menu.offsetWidth}px`;
	});
}
</pre>
    </article>
</section>





		</div>
	</div>

	<div class="clearfix"></div>

	

</div>
</div>


    <div class="modal fade" id="searchResults">
      <div class="modal-dialog">
        <div class="modal-content">
          <div class="modal-header">
            <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
            <h4 class="modal-title">Search results</h4>
          </div>
          <div class="modal-body"></div>
          <div class="modal-footer">
            <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
          </div>
        </div><!-- /.modal-content -->
      </div><!-- /.modal-dialog -->
    </div>


<footer>


<span class="jsdoc-message">
	Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.5.5</a>
	
		on 2019-01-04T18:17:00+08:00
	
	using the <a href="https://github.com/docstrap/docstrap">DocStrap template</a>.
</span>
</footer>

<script src="scripts/docstrap.lib.js"></script>
<script src="scripts/toc.js"></script>

    <script type="text/javascript" src="scripts/fulltext-search-ui.js"></script>


<script>
$( function () {
	$( "[id*='$']" ).each( function () {
		var $this = $( this );

		$this.attr( "id", $this.attr( "id" ).replace( "$", "__" ) );
	} );

	$( ".tutorial-section pre, .readme-section pre, pre.prettyprint.source" ).each( function () {
		var $this = $( this );

		var example = $this.find( "code" );
		exampleText = example.html();
		var lang = /{@lang (.*?)}/.exec( exampleText );
		if ( lang && lang[1] ) {
			exampleText = exampleText.replace( lang[0], "" );
			example.html( exampleText );
			lang = lang[1];
		} else {
			var langClassMatch = example.parent()[0].className.match(/lang\-(\S+)/);
			lang = langClassMatch ? langClassMatch[1] : "javascript";
		}

		if ( lang ) {

			$this
			.addClass( "sunlight-highlight-" + lang )
			.addClass( "linenums" )
			.html( example.html() );

		}
	} );

	Sunlight.highlightAll( {
		lineNumbers : true,
		showMenu : true,
		enableDoclinks : true
	} );

	$.catchAnchorLinks( {
        navbarOffset: 10
	} );
	$( "#toc" ).toc( {
		anchorName  : function ( i, heading, prefix ) {
			return $( heading ).attr( "id" ) || ( prefix + i );
		},
		selectors   : "#toc-content h1,#toc-content h2,#toc-content h3,#toc-content h4",
		showAndHide : false,
		smoothScrolling: true
	} );

	$( "#main span[id^='toc']" ).addClass( "toc-shim" );
	$( '.dropdown-toggle' ).dropdown();

    $( "table" ).each( function () {
      var $this = $( this );
      $this.addClass('table');
    } );

} );
</script>



<!--Navigation and Symbol Display-->


<!--Google Analytics-->



    <script type="text/javascript">
        $(document).ready(function() {
            SearcherDisplay.init();
        });
    </script>


</body>
</html>
